<html>
<head>
  <script src="sorttable.js"></script>
  <script src="sourceview.js"></script>
  <link rel="stylesheet" type="text/css" href="style.css">
  <title>zcov: /home/vagrant/workspace/proj_example/cov/example.c</title>
</head>
<body>
<center><h1> zcov: <a href="index.html">/home/vagrant/workspace/proj_example/cov</a>/<a href="example.c.html">example.c</a> </h1></center>
<hr>


<center>
<table id="headertable" cellpadding=2>
  <tr>
    <td bgcolor=#ACACFF> <b>Files:</b> </td>
    <td bgcolor=#F0F0FF> 1 </td>
    <td width="30"></td>
    <td bgcolor=#ACACFF> <b>Branches&nbsp;Taken:</b> </td>
    <td bgcolor=#F0F0FF align=right> <b>59.4%<b> </td>
    <td bgcolor=#F0F0FF align=right> 19&nbsp;/&nbsp;32 </td>
  </tr>
  <tr>
    <td bgcolor=#ACACFF> <b>Generated:</b> </td>
    <td bgcolor=#F0F0FF> 2016-04-12&nbsp;14:20 </td>
    <td width="30"></td>
    <td bgcolor=#ACACFF> <b>Branches&nbsp;Executed:</b> </td>
    <td bgcolor=#F0F0FF align=right> <b>81.2%<b> </td>
    <td bgcolor=#F0F0FF align=right> 26&nbsp;/&nbsp;32 </td>
  </tr>
  <tr>
    <td colspan=2> </td>
    <td width="30"></td>
    <td bgcolor=#ACACFF> <b>Line&nbsp;Coverage:</b> </td>
    <td bgcolor=#F0F0FF align=right> <b>73.0%</b> </td>
    <td bgcolor=#F0F0FF align=right> 54&nbsp;/&nbsp;74 </td>
  </tr>
</table>
</center>
<p>
<hr>

<center>
<table id="fileheadertable" cellpadding=2>
  <tr>
    <td bgcolor=#ACACFF> <b>Programs:</b> </td>
    <td bgcolor=#F0F0FF> 1 </td>
    <td width="30"></td>
    <td bgcolor=#ACACFF> <b>Runs</b> </td>
    <td bgcolor=#F0F0FF align=right> 49 </td>
  </tr>
</table>
</center>
<p>
<hr>

<pre>
<span class="lineNum">       1 </span>                : #<B><FONT COLOR="#5F9EA0">include</FONT></B> <B><FONT COLOR="#BC8F8F">&lt;ctype.h&gt;</FONT></B>
<span class="lineNum">       2 </span>                : #<B><FONT COLOR="#5F9EA0">include</FONT></B> <B><FONT COLOR="#BC8F8F">&lt;stdio.h&gt;</FONT></B>
<span class="lineNum">       3 </span>                : #<B><FONT COLOR="#5F9EA0">include</FONT></B> <B><FONT COLOR="#BC8F8F">&lt;stdlib.h&gt;</FONT></B>
<span class="lineNum">       4 </span>                : #<B><FONT COLOR="#5F9EA0">include</FONT></B> <B><FONT COLOR="#BC8F8F">&lt;unistd.h&gt;</FONT></B>
<span class="lineNum">       5 </span>                : #<B><FONT COLOR="#5F9EA0">include</FONT></B> <B><FONT COLOR="#BC8F8F">&lt;string.h&gt;</FONT></B>
<span class="lineNum">       6 </span>                : 
<span class="lineNum">       7 </span>                : <B><FONT COLOR="#228B22">int</FONT></B> buffer[256];
<span class="lineNum">       8 </span>                : 
<span class="lineNum">       9 </span><span class="lineCov">              48: <B><FONT COLOR="#228B22">void</FONT></B> <B><FONT COLOR="#0000FF">init_buffer</FONT></B>(){</span>
<span class="lineNum">      10 </span>                :   <B><FONT COLOR="#228B22">int</FONT></B> i;
<span class="branchGroup"><span class="lineNum">         </span><span class="branchTaken">           12288: branch 0 taken</span>
<span class="lineNum">         </span><span class="branchTaken">              48: branch 1 taken</span>
</span><span class="lineNum">      11 </span><span class="lineCov">           12336:   <B><FONT COLOR="#A020F0">for</FONT></B> (i = 0; i &lt; 256; ++i){</span>
<span class="lineNum">      12 </span><span class="lineCov">           12288:     buffer[i] = i;</span>
<span class="lineNum">      13 </span>                :   }
<span class="lineNum">      14 </span><span class="lineCov">              48: }</span>
<span class="lineNum">      15 </span>                : 
<span class="lineNum">      16 </span><span class="lineCov">              49: <B><FONT COLOR="#228B22">int</FONT></B> <B><FONT COLOR="#0000FF">processing_data</FONT></B>(<B><FONT COLOR="#228B22">char</FONT></B> * filename) {</span>
<span class="lineNum">      17 </span>                : 
<span class="lineNum">      18 </span>                :   <B><FONT COLOR="#228B22">char</FONT></B> stack_buffer[32];
<span class="lineNum">      19 </span><span class="lineCov">              49:   <B><FONT COLOR="#228B22">char</FONT></B>* heap_buffer = malloc(32);</span>
<span class="lineNum">      20 </span>                : 
<span class="lineNum">      21 </span>                :   FILE * fp;
<span class="lineNum">      22 </span><span class="lineCov">              49:   <B><FONT COLOR="#228B22">char</FONT></B> * line = NULL;</span>
<span class="lineNum">      23 </span><span class="lineCov">              49:   size_t len = 0;</span>
<span class="lineNum">      24 </span>                :   ssize_t read;
<span class="lineNum">      25 </span>                : 
<span class="lineNum">      26 </span><span class="lineCov">              49:   fp = fopen(filename, <B><FONT COLOR="#BC8F8F">&quot;r&quot;</FONT></B>);</span>
<span class="branchGroup"><span class="lineNum">         </span><span class="branchNotTaken">               0: branch 0 not taken</span>
<span class="lineNum">         </span><span class="branchTaken">              49: branch 1 taken</span>
</span><span class="lineNum">      27 </span><span class="lineCov">              49:   <B><FONT COLOR="#A020F0">if</FONT></B> (fp == NULL)</span>
<span class="lineNum">      28 </span><span class="lineNoCov">               0:     exit(EXIT_FAILURE);</span>
<span class="lineNum">      29 </span>                : 
<span class="lineNum">      30 </span>                :   <I><FONT COLOR="#B22222">// processing lines in file
<span class="branchGroup"><span class="lineNum">         </span><span class="branchTaken">             623: branch 1 taken</span>
<span class="lineNum">         </span><span class="branchTaken">              49: branch 2 taken</span>
</span><span class="lineNum">      31 </span><span class="lineCov">             721: </FONT></I>  <B><FONT COLOR="#A020F0">while</FONT></B> ((read = getline(&amp;line, &amp;len, fp)) != -1) {</span>
<span class="lineNum">      32 </span>                :     <I><FONT COLOR="#B22222">//printf(&quot;parsing line of length %zu :&quot;, read);
<span class="lineNum">      33 </span><span class="lineCov">             623: </FONT></I>    printf(<B><FONT COLOR="#BC8F8F">&quot;read&gt; %s&quot;</FONT></B>, line);</span>
<span class="lineNum">      34 </span>                : 
<span class="lineNum">      35 </span>                :     <I><FONT COLOR="#B22222">// skip short lines
<span class="branchGroup"><span class="lineNum">         </span><span class="branchTaken">             299: branch 0 taken</span>
<span class="lineNum">         </span><span class="branchTaken">             324: branch 1 taken</span>
</span><span class="lineNum">      36 </span><span class="lineCov">             623: </FONT></I>    <B><FONT COLOR="#A020F0">if</FONT></B>(read &lt; 5)</span>
<span class="lineNum">      37 </span><span class="lineCov">             299:       <B><FONT COLOR="#A020F0">continue</FONT></B>;</span>
<span class="lineNum">      38 </span>                : 
<span class="lineNum">      39 </span>                :     <I><FONT COLOR="#B22222">// BUG: BUFFER OVERFLOW
<span class="lineNum">      40 </span>                : </FONT></I>    <I><FONT COLOR="#B22222">// line starts with &quot;stack&quot;, load rest of line to stack_buff
<span class="branchGroup"><span class="lineNum">         </span><span class="branchTaken">              26: branch 0 taken</span>
<span class="lineNum">         </span><span class="branchTaken">             298: branch 1 taken</span>
</span><span class="lineNum">      41 </span><span class="lineCov">             324: </FONT></I>    <B><FONT COLOR="#A020F0">if</FONT></B>(!strncmp(line,<B><FONT COLOR="#BC8F8F">&quot;stack&quot;</FONT></B>,5)){</span>
<span class="lineNum">      42 </span>                :       <I><FONT COLOR="#B22222">//printf(&quot;found mem load marker\n&quot;);
<span class="lineNum">      43 </span><span class="lineCov">              26: </FONT></I>      <B><FONT COLOR="#228B22">char</FONT></B> copy[read-5];</span>
<span class="lineNum">      44 </span><span class="lineCov">              26:       strncpy(copy, line+5, strlen(line)-1);</span>
<span class="lineNum">      45 </span><span class="lineCov">              26:       strcpy(stack_buffer, copy);</span>
<span class="lineNum">      46 </span><span class="lineCov">              26:       printf(<B><FONT COLOR="#BC8F8F">&quot;load to stack: %s&quot;</FONT></B>, stack_buffer);</span>
<span class="lineNum">      47 </span><span class="lineCov">              26:       <B><FONT COLOR="#A020F0">continue</FONT></B>;</span>
<span class="lineNum">      48 </span>                :     }
<span class="lineNum">      49 </span>                : 
<span class="lineNum">      50 </span>                :     <I><FONT COLOR="#B22222">// BUG: DIV BY ZERO             
<span class="lineNum">      51 </span>                : </FONT></I>    <I><FONT COLOR="#B22222">// line starts with &quot;value&quot;
<span class="branchGroup"><span class="lineNum">         </span><span class="branchTaken">              23: branch 0 taken</span>
<span class="lineNum">         </span><span class="branchTaken">             275: branch 1 taken</span>
</span><span class="lineNum">      52 </span><span class="lineCov">             298: </FONT></I>    <B><FONT COLOR="#A020F0">if</FONT></B>(!strncmp(line,<B><FONT COLOR="#BC8F8F">&quot;value&quot;</FONT></B>,5)){</span>
<span class="lineNum">      53 </span>                :       <I><FONT COLOR="#B22222">//printf(&quot;found mem load marker\n&quot;);
<span class="lineNum">      54 </span><span class="lineCov">              23: </FONT></I>      <B><FONT COLOR="#228B22">char</FONT></B> copy[read-5];</span>
<span class="lineNum">      55 </span><span class="lineCov">              23:       strncpy(copy, line+5, strlen(line)-1);</span>
<span class="lineNum">      56 </span><span class="lineCov">              23:       <B><FONT COLOR="#228B22">int</FONT></B> value = atoi(copy);</span>
<span class="lineNum">      57 </span><span class="lineCov">              23:       <B><FONT COLOR="#228B22">float</FONT></B> a = (100/(42-value));</span>
<span class="lineNum">      58 </span><span class="lineCov">              23:       printf(<B><FONT COLOR="#BC8F8F">&quot;\ncalc 100/(42-%d) \n&quot;</FONT></B>,value);        <I><FONT COLOR="#B22222">// found by KLEE (and AFL)</span>
<span class="lineNum">      59 </span><span class="lineCov">              23: </FONT></I>      printf(<B><FONT COLOR="#BC8F8F">&quot;= %f\n&quot;</FONT></B>,a);</span>
<span class="lineNum">      60 </span><span class="lineCov">              23:       <B><FONT COLOR="#A020F0">continue</FONT></B>;</span>
<span class="lineNum">      61 </span>                :     }
<span class="lineNum">      62 </span>                : 
<span class="lineNum">      63 </span>                :     <I><FONT COLOR="#B22222">// BUG: OUT OF BOUNDS READ
<span class="lineNum">      64 </span>                : </FONT></I>    <I><FONT COLOR="#B22222">// found by AFL
<span class="branchGroup"><span class="lineNum">         </span><span class="branchTaken">              48: branch 0 taken</span>
<span class="lineNum">         </span><span class="branchTaken">             227: branch 1 taken</span>
</span><span class="lineNum">      65 </span><span class="lineCov">             275: </FONT></I>    <B><FONT COLOR="#A020F0">if</FONT></B>(!strncmp(line,<B><FONT COLOR="#BC8F8F">&quot;buffr&quot;</FONT></B>,5)){</span>
<span class="lineNum">      66 </span>                :       <I><FONT COLOR="#B22222">//printf(&quot;found mem load marker\n&quot;);
<span class="lineNum">      67 </span><span class="lineCov">              48: </FONT></I>      init_buffer();</span>
<span class="lineNum">      68 </span><span class="lineCov">              48:       <B><FONT COLOR="#228B22">char</FONT></B> copy[read-5];</span>
<span class="lineNum">      69 </span><span class="lineCov">              48:       strncpy(copy, line+5, strlen(line)-1);</span>
<span class="lineNum">      70 </span><span class="lineCov">              48:       <B><FONT COLOR="#228B22">int</FONT></B> value = atoi(copy);</span>
<span class="lineNum">      71 </span><span class="lineCov">              48:       printf(<B><FONT COLOR="#BC8F8F">&quot;\nread value from buffer[%d]\n&quot;</FONT></B>,value);</span>
<span class="lineNum">      72 </span><span class="lineCov">              48:       printf(<B><FONT COLOR="#BC8F8F">&quot;= %d\n&quot;</FONT></B>,buffer[value]);</span>
<span class="lineNum">      73 </span>                : 
<span class="lineNum">      74 </span><span class="lineCov">              48:       printf(<B><FONT COLOR="#BC8F8F">&quot;\ncalc 100/(42-buffer[%d]) \n&quot;</FONT></B>, buffer[value]);</span>
<span class="lineNum">      75 </span><span class="lineCov">              48:       <B><FONT COLOR="#228B22">float</FONT></B> a = (100/(42-buffer[value]));</span>
<span class="lineNum">      76 </span><span class="lineCov">              48:       printf(<B><FONT COLOR="#BC8F8F">&quot;= %f\n&quot;</FONT></B>,a);</span>
<span class="lineNum">      77 </span><span class="lineCov">              48:       <B><FONT COLOR="#A020F0">continue</FONT></B>;</span>
<span class="lineNum">      78 </span>                :     }
<span class="lineNum">      79 </span>                : 
<span class="lineNum">      80 </span>                :   }
<span class="lineNum">      81 </span>                : 
<span class="lineNum">      82 </span><span class="lineCov">              49:   <B><FONT COLOR="#A020F0">return</FONT></B> 0;</span>
<span class="lineNum">      83 </span>                : } 
<span class="lineNum">      84 </span>                : 
<span class="lineNum">      85 </span><span class="lineCov">              49: <B><FONT COLOR="#228B22">int</FONT></B> <B><FONT COLOR="#0000FF">main</FONT></B> (<B><FONT COLOR="#228B22">int</FONT></B> argc, <B><FONT COLOR="#228B22">char</FONT></B> **argv){</span>
<span class="lineNum">      86 </span><span class="lineCov">              49:   <B><FONT COLOR="#228B22">int</FONT></B> hflag = 0;</span>
<span class="lineNum">      87 </span><span class="lineCov">              49:   <B><FONT COLOR="#228B22">char</FONT></B>* file_input = NULL;</span>
<span class="lineNum">      88 </span>                :   <B><FONT COLOR="#228B22">int</FONT></B> index;
<span class="lineNum">      89 </span>                :   <B><FONT COLOR="#228B22">int</FONT></B> c;
<span class="lineNum">      90 </span><span class="lineCov">              49:   <B><FONT COLOR="#228B22">int</FONT></B> heap_mode = 0;</span>
<span class="lineNum">      91 </span><span class="lineCov">              49:   <B><FONT COLOR="#228B22">int</FONT></B> stack_mode = 0;</span>
<span class="lineNum">      92 </span>                : 
<span class="lineNum">      93 </span><span class="lineCov">              49:   opterr = 0;</span>
<span class="branchGroup"><span class="lineNum">         </span><span class="branchTaken">              49: branch 1 taken</span>
<span class="lineNum">         </span><span class="branchTaken">              49: branch 2 taken</span>
</span><span class="lineNum">      94 </span><span class="lineCov">             147:   <B><FONT COLOR="#A020F0">while</FONT></B> ((c = getopt (argc, argv, <B><FONT COLOR="#BC8F8F">&quot;hf:&quot;</FONT></B>)) != -1)</span>
<span class="branchGroup"><span class="lineNum">         </span><span class="branchNotTaken">               0: branch 0 not taken</span>
<span class="lineNum">         </span><span class="branchTaken">              49: branch 1 taken</span>
<span class="lineNum">         </span><span class="branchNotTaken">               0: branch 2 not taken</span>
<span class="lineNum">         </span><span class="branchNotTaken">               0: branch 3 not taken</span>
</span><span class="lineNum">      95 </span><span class="lineCov">              49:     <B><FONT COLOR="#A020F0">switch</FONT></B> (c){</span>
<span class="lineNum">      96 </span><span class="lineNoCov">               0:       <B><FONT COLOR="#A020F0">case</FONT></B> <B><FONT COLOR="#BC8F8F">'h'</FONT></B>: hflag = 1; <B><FONT COLOR="#A020F0">break</FONT></B>;</span>
<span class="lineNum">      97 </span><span class="lineCov">              49:       <B><FONT COLOR="#A020F0">case</FONT></B> <B><FONT COLOR="#BC8F8F">'f'</FONT></B>: file_input = optarg; <B><FONT COLOR="#A020F0">break</FONT></B>;</span>
<span class="lineNum">      98 </span>                :       <B><FONT COLOR="#A020F0">case</FONT></B> <B><FONT COLOR="#BC8F8F">'?'</FONT></B>:
<span class="branchGroup"><span class="lineNum">         </span><span class="branchNotTaken">               0: branch 0 not taken</span>
<span class="lineNum">         </span><span class="branchNotTaken">               0: branch 1 not taken</span>
</span><span class="lineNum">      99 </span><span class="lineNoCov">               0:         <B><FONT COLOR="#A020F0">if</FONT></B> (optopt == <B><FONT COLOR="#BC8F8F">'f'</FONT></B>)</span>
<span class="lineNum">     100 </span><span class="lineNoCov">               0:           fprintf (stderr, <B><FONT COLOR="#BC8F8F">&quot;Option -%c requires input file\n&quot;</FONT></B>, optopt);</span>
<span class="branchGroup"><span class="lineNum">         </span><span class="branchNotTaken">               0: branch 1 not taken</span>
<span class="lineNum">         </span><span class="branchNotTaken">               0: branch 2 not taken</span>
</span><span class="lineNum">     101 </span><span class="lineNoCov">               0:         <B><FONT COLOR="#A020F0">else</FONT></B> <B><FONT COLOR="#A020F0">if</FONT></B> (isprint (optopt))</span>
<span class="lineNum">     102 </span><span class="lineNoCov">               0:           fprintf (stderr, <B><FONT COLOR="#BC8F8F">&quot;Unknown option `-%c'.\n&quot;</FONT></B>, optopt);</span>
<span class="lineNum">     103 </span>                :         <B><FONT COLOR="#A020F0">else</FONT></B>
<span class="lineNum">     104 </span><span class="lineNoCov">               0:           fprintf (stderr, <B><FONT COLOR="#BC8F8F">&quot;Unknown option character `\\x%x'.\n&quot;</FONT></B>, optopt);</span>
<span class="lineNum">     105 </span><span class="lineNoCov">               0:         <B><FONT COLOR="#A020F0">return</FONT></B> 1;</span>
<span class="lineNum">     106 </span>                :       <B><FONT COLOR="#5F9EA0">default</FONT></B>:
<span class="lineNum">     107 </span><span class="lineNoCov">               0:         abort ();</span>
<span class="lineNum">     108 </span>                :     }
<span class="lineNum">     109 </span>                : 
<span class="branchGroup"><span class="lineNum">         </span><span class="branchNotTaken">               0: branch 0 not taken</span>
<span class="lineNum">         </span><span class="branchTaken">              49: branch 1 taken</span>
</span><span class="lineNum">     110 </span><span class="lineCov">              49:   <B><FONT COLOR="#A020F0">for</FONT></B> (index = optind; index &lt; argc; index++){</span>
<span class="lineNum">     111 </span><span class="lineNoCov">               0:     printf (<B><FONT COLOR="#BC8F8F">&quot;Non-option argument %s\n&quot;</FONT></B>, argv[index]);</span>
<span class="lineNum">     112 </span>                :     <I><FONT COLOR="#B22222">// here you can find an official not suported option \o/
<span class="branchGroup"><span class="lineNum">         </span><span class="branchNotTaken">               0: branch 0 not taken</span>
<span class="lineNum">         </span><span class="branchNotTaken">               0: branch 1 not taken</span>
</span><span class="lineNum">     113 </span><span class="lineNoCov">               0: </FONT></I>    <B><FONT COLOR="#A020F0">if</FONT></B>(!strcmp(argv[index], <B><FONT COLOR="#BC8F8F">&quot;secret_mode&quot;</FONT></B>)){</span>
<span class="lineNum">     114 </span><span class="lineNoCov">               0:       printf(<B><FONT COLOR="#BC8F8F">&quot;You found the super secret mode!\n&quot;</FONT></B>);</span>
<span class="lineNum">     115 </span><span class="lineNoCov">               0:       <B><FONT COLOR="#A020F0">return</FONT></B> 0;</span>
<span class="lineNum">     116 </span>                :     }
<span class="lineNum">     117 </span>                :   }
<span class="lineNum">     118 </span>                : 
<span class="branchGroup"><span class="lineNum">         </span><span class="branchNotTaken">               0: branch 0 not taken</span>
<span class="lineNum">         </span><span class="branchTaken">              49: branch 1 taken</span>
</span><span class="lineNum">     119 </span><span class="lineCov">              49:   <B><FONT COLOR="#A020F0">if</FONT></B>(hflag){</span>
<span class="lineNum">     120 </span><span class="lineNoCov">               0:       printf(<B><FONT COLOR="#BC8F8F">&quot;Helptext: &quot;</FONT></B>);</span>
<span class="lineNum">     121 </span><span class="lineNoCov">               0:       printf(<B><FONT COLOR="#BC8F8F">&quot;One can use one of the following options:\n&quot;</FONT></B>);</span>
<span class="lineNum">     122 </span><span class="lineNoCov">               0:       printf(<B><FONT COLOR="#BC8F8F">&quot;-h\t\tshow this help text\n&quot;</FONT></B>);</span>
<span class="lineNum">     123 </span><span class="lineNoCov">               0:       printf(<B><FONT COLOR="#BC8F8F">&quot;-f &lt;file&gt;\tdo calc based on a file input\n&quot;</FONT></B>);</span>
<span class="lineNum">     124 </span><span class="lineNoCov">               0:       printf(<B><FONT COLOR="#BC8F8F">&quot;???\t\tmore options still under development\n&quot;</FONT></B>);    </span>
<span class="lineNum">     125 </span><span class="lineNoCov">               0:       <B><FONT COLOR="#A020F0">return</FONT></B> 0;</span>
<span class="lineNum">     126 </span>                :     }
<span class="lineNum">     127 </span>                :   
<span class="branchGroup"><span class="lineNum">         </span><span class="branchTaken">              49: branch 0 taken</span>
<span class="lineNum">         </span><span class="branchNotTaken">               0: branch 1 not taken</span>
</span><span class="lineNum">     128 </span><span class="lineCov">              49:   <B><FONT COLOR="#A020F0">if</FONT></B>(file_input){</span>
<span class="lineNum">     129 </span><span class="lineCov">              49:     processing_data(file_input);</span>
<span class="lineNum">     130 </span><span class="lineCov">              49:     <B><FONT COLOR="#A020F0">return</FONT></B> 0;</span>
<span class="lineNum">     131 </span>                :   }
<span class="lineNum">     132 </span>                : 
<span class="lineNum">     133 </span><span class="lineNoCov">               0:   <B><FONT COLOR="#A020F0">return</FONT></B> 0;</span>
<span class="lineNum">     134 </span>                : }
<span class="lineNum">     135 </span>                : 
<span class="lineNum">     136 </span>                : 
</pre>
<hr>
Generated: 2016-04-12&nbsp;14:20 by <a href="http://minormatter.com/zcov">zcov</a><br>
</body>
</html>
